package com.gitee.zycra.future.job.common.util;

import com.alibaba.ttl.TransmittableThreadLocal;

/**
 * @author zycra
 */
public final class UserInfoUtil {

    private static final ThreadLocal<Long> USER_ID = new TransmittableThreadLocal<>();

    private static final ThreadLocal<String> USERNAME = new TransmittableThreadLocal<>();

    private UserInfoUtil() {
    }

    public static Long getUserId() {
        return USER_ID.get();
    }

    public static String getUsername() {
        return USERNAME.get();
    }

    public static void setValue(Long userId, String username) {
        USER_ID.set(userId);
        USERNAME.set(username);
    }

    public static void removeValue() {
        USER_ID.remove();
        USERNAME.remove();
    }
}
